<?php
/**
 * Author: Administrator
 * Date: 2022/7/23 2:03
 */

namespace DesignPatterns\Behavioral\State;


use function PHPUnit\Framework\throwException;

class OrderFactory
{
    public static function getOrder($id) {
        $order = new OrderModel($id);
        switch ($order->state) {
            case 'shipping':
                return new ShippingOrder($order);
            case 'created':
                return new CreatedOrder($order);
            case 'complete':
                return new CompleteOrder($order);
            default:
                throw new \Exception('Unknown state: '.$order->state);
        }
    }
}